package com.yyjj.hangqing.activity;

import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.aries.ui.view.title.TitleBarView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.yyjj.hangqing.R;
import com.yyjj.hangqing.adapter.FundListAdapter;
import com.yyjj.hangqing.adapter.HuoQiBaoAdapter;
import com.yyjj.hangqing.api.Api;
import com.yyjj.hangqing.entity.BaseTResp;
import com.yyjj.hangqing.entity.FundEntity;
import com.yyjj.hangqing.entity.HuoQiBaoEntity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import tech.com.commoncore.app.FastManager;
import tech.com.commoncore.base.BaseRefreshLoadActivity;
import tech.com.commoncore.base.BaseTitleActivity;
import tech.com.commoncore.constant.ApiConstant;
import tech.com.commoncore.view.SpaceItemDecoration;

/**
 * 活期宝
 */
@Route(path = "/hq/HuoQiBao")
public class HuoQiBaoActivity extends BaseRefreshLoadActivity{

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText("活期宝");
    }

    @Override
    public int getContentLayout() {
        return R.layout.hq_activity_huo_qi_bao;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        mRecyclerView.addItemDecoration(new SpaceItemDecoration(1));

    }

    @Override
    public BaseQuickAdapter getAdapter() {
        return new HuoQiBaoAdapter(R.layout.hq_item_huoqibao_list);
    }

    @Override
    public void loadData(int page) {
//        https://d.wanjinig.cn/yapi/fund/huoqibao?name=huoqibao
//        https://d.wanjinig.cn/new_api/Quotes/getSinaQuotesList?node=open_fund&type=9&page=1&num=10&symbol=%20&sort=symbol&asc=1&is_cache=0
//        https://d.wanjinig.cn/new_api/Quotes/getSinaQuotesList?node=open_fund&type=9&page=1&num=10&symbol=%20&sort=symbol&asc=1&name=%E9%BB%84%E9%87%91%E8%BF%9E%E7%BB%AD&is_cache=0
//        https://d.wanjinig.cn/new_api/Quotes/getSinaQuotesList?node=open_fund&type=9&page=1&num=10&symbol=%20&sort=symbol&asc=1&is_cache=0
        ViseHttp.GET(Api.HUOQIBAO)
                .baseUrl(ApiConstant.BASE_URL)
                .addParam("node","open_fund")
                .addParam("type","9")
                .addParam("page",1+page+"")
                .addParam("num","10")
//                .addParam("symbol","%20")
                .addParam("sort","symbol")
                .addParam("asc","1")
                .addParam("is_cache","0")
                .request(new ACallback<BaseTResp<ArrayList<HuoQiBaoEntity>>>() {
                    @Override
                    public void onSuccess(BaseTResp<ArrayList<HuoQiBaoEntity>> data) {
                        if(data.code ==1 && data.data != null){
                            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(),data.data,null);
                        }else{
                            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(),null,null);
                        }
                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                        FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(),null,null);
                    }
                });
    }
}
